home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Blitz2 / BlitzFaq / FaqLists / 2ndmouse.txt next >
Encoding:
Text File  |  1996-08-31  |  1.2 KB  |  63 lines

  1. NEWTYPE .Dat
  2.   Reg.l:  X.w:  Y.w:  cx.w:  cy.w
  3.   MinX.w: MinY.w: MaxX.w: MaxY.w
  4. End NEWTYPE
  5. Dim M.Dat(1)
  6. M.Dat(0)\Reg=$dff00a ;Hardware reg for port 1 (mouse)
  7. M.Dat(1)\Reg=$dff00c ;Hardware reg for port 2 (joy)
  8. M.Dat(0)\MaxX=319;  Set max x boundary to 319
  9. M.Dat(0)\MaxY=255;  Set max y boundary to 255
  10. M.Dat(1)\MaxX=319;  Set max x boundary to 319
  11. M.Dat(1)\MaxY=255;  Set max y boundary to 255
  12.  
  13. Statement ReadMouse{Port}
  14.   SHARED M.Dat()
  15.  
  16.   USEPATH M.Dat(Port)
  17.   ocx.w=\cx
  18.   ocy.w=\cy
  19.  
  20.   ; This is where the reading from the hardware regs is done
  21.   \cx=Peek.b(\Reg+1)
  22.   \cy=Peek.b(\Reg)
  23.  
  24.   ; Here the deltas are calculated
  25.   dx.w=\cx-ocx: dy.w=\cy-ocy
  26.  
  27.   ; Wrap around counters
  28.   If(dx<-127)  dx+256
  29.   If(dx>127)   dx-256
  30.   If(dy<-127)  dy+256
  31.   If(dy>127)   dy-256
  32.  
  33.   ;Update coords
  34.   \X+dx:  \Y+dy
  35.  
  36.   ;Don't you go beyond your limits
  37.   If(\X>\MaxX)  \X=\MaxX
  38.   If(\X<\MinX)  \X=\MinX
  39.   If(\Y>\MaxY)  \Y=\MaxY
  40.   If(\Y<\MinY)  \Y=\MinY
  41. End Statement
  42.  
  43. BLITZ
  44. Slice 0,44,2
  45. BitMap 0,320,256,2
  46. Cls 0
  47. Line 0,0,5,5,1
  48. GetaShape 0,0,0,6,6
  49. GetaSprite 0,0
  50. Cls 0
  51. Show 0
  52.  
  53.  
  54. BitMapOutput 0
  55. ; This is the loop you'd need
  56. Repeat
  57.   ReadMouse{0}
  58.   ReadMouse{1}
  59.   ShowSprite 0,M.Dat(0)\X,M.Dat(0)\Y,0
  60.   ShowSprite 0,M.Dat(1)\X,M.Dat(1)\Y,2
  61.   VWait
  62. Until Joyb(0)
  63. End